<template>
  <div>
    <!--搜索-->
    <el-row>
      <el-col :span="5">
        <el-input placeholder="请输入用户id" v-model="queryInfo.content" :clearable="true" @clear="search"
          @keyup.native.enter="search" size="small" style="min-width: 500px">
          <el-button slot="append" icon="el-icon-search" @click="search"></el-button>
        </el-input>
      </el-col>
    </el-row>

    <el-table :data="userList">
      <el-table-column label="序号" type="index" width="50"></el-table-column>
      <el-table-column label="咨询师id" prop="cid" show-overflow-tooltip></el-table-column>
      <el-table-column label="个人介绍" prop="introduce" show-overflow-tooltip></el-table-column>
      <el-table-column label="擅长领域" prop="territory" width="150"></el-table-column>
      <el-table-column label="咨询人次" prop="number" width="150"></el-table-column>
      <el-table-column label="从业年数" prop="year" width="150"></el-table-column>
      <el-table-column label="地址" prop="address" width="150"></el-table-column>
      <el-table-column label="申请用户id" prop="id" width="150"></el-table-column>

      <el-table-column label="审核状态" width="80">
        <template v-slot="scope">
          <el-switch v-model="scope.row.state" @change="userStatusChanged(scope.row)"></el-switch>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="200">
        <template v-slot="scope">
          <el-popconfirm title="确定删除吗？" icon="el-icon-delete" iconColor="red" @onConfirm="deleteUserById(scope.row)">
            <el-button size="mini" type="danger" icon="el-icon-delete" slot="reference">删除</el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>

    <!--分页-->
    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
      :current-page="queryInfo.pageNum" :page-sizes="[10, 20, 30, 50]" :page-size="queryInfo.pageSize" :total="total"
      layout="total, sizes, prev, pager, next, jumper" background>
    </el-pagination>
    
    
  </div>


</template>

<script>
  import Breadcrumb from "@/components/Breadcrumb";
  import {
    updateStatus,
    deleteByCid,
    getApplyList
  } from '@/api/user'

  export default {
    name: 'doctorApply',
    components: {
      Breadcrumb
    },
    data() {
      return {
        queryInfo: {
          content: '', // categoryId: null,
          pageNum: 1,
          pageSize: 10
        },
        userList: [],
        total: 0,
        userId: 0, //被修改的用户id
      }
    },
    created() {
      this.getUserList();
    },
    methods: {
      getUserList() {
        getApplyList(this.queryInfo).then(res => {
          res = res.data;
          if (res.code == 1) {
            console.log('查询成功')
            // this.userList = res.data;
            this.userList = res.data.records;
            this.total = res.data.total;
          }
        })
      },
      //监听 pageSize 改变事件
      handleSizeChange(newSize) {
        this.queryInfo.pageSize = newSize
        this.getData()
      },
      //监听页码改变的事件
      handleCurrentChange(newPage) {
        this.queryInfo.pageNum = newPage
        this.getData()
      },
      search() {
        alert("搜索");
      },
      deleteUserById(apply) {
        // alert("删除审核" + apply.cid);
        deleteByCid(apply.cid).then(res=>{
          res = res.data;
          if (res.code == 1){
            this.msgSuccess(res.msg);
            this.getUserList();
          }
        })
      },
      userStatusChanged(apply) {
        // alert("修改审核状态" + apply.status);
        if (apply.state){
          apply.state = 1;
        }else {
          apply.state = 0;
        }
        updateStatus(apply).then(res=>{
          res = res.data;
          if (res.code == 1){
            this.msgSuccess(res.msg);
          }
        })
        if (apply.state == 1){
          apply.state = true;
        }else {
          apply.state = false;
        }
      }
    }
  }
</script>

<style>
</style>